package com.zf.search;

import java.util.List;

/**
 * @ProjectName: DataStructures
 * @Package: com.zf.search
 * @ClassName: InsertVSearch
 * @Author: zf
 * @Description:
 * @Date: 2020/10/28 14:27
 * @Version: 1.0
 */
public class InsertVSearch {
    public static void main(String[] args) {
        int[] arr = new int[100];
        for (int i = 0; i < 100; i++) {
            arr[i] = i + 1;
        }

        int resIndex = insertVSearch(arr, 0, arr.length - 1, 101);
        System.out.println("resIndex=" + resIndex);
    }

    public static int insertVSearch(int[] arr, int left, int right, int findVal){
        if (left > right){
            return -1;
        }
        int mid = left + (right - left)*(findVal - arr[left])/(arr[right] - arr[left]);
        int midVal = arr[mid];


        if (findVal > arr[mid]){
            return insertVSearch(arr,mid + 1, right, findVal);
        }else if (findVal < arr[mid]){
            return insertVSearch(arr, left, mid - 1, findVal);
        }else {
            return mid;
        }

    }
}
